package reflect;
import java.lang.reflect.Field;
public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
        Teacher t = new Teacher();
        t.name = "王克晶";
        System.out.println(t);

        Class cls = Class.forName("reflect.Teacher");
        Object obj = cls.newInstance();
        //获取名为name的属性
        Field field = cls.getField("name");
        field.set(obj,"范传奇");//obj.name="范传奇"
        System.out.println(obj);
        //获取属性的值
        System.out.println(field.get(obj));
    }
}
